package com.example.hotel.common;

public class JsonResult <T> {

    /*
      统一返回的工具类
     */

        private Integer code ; //返回给前端的状态码
        private String message ; //返回给前端的提示信息
        private T data ;
        public static <T> JsonResult<T> ok(Integer code,String message,T data){
            return new JsonResult<>(code,message,data);
        }
        public static <T> JsonResult<T> ok(String message){
            return new JsonResult<>(2000,message,null);
        }
        public static <T> JsonResult<T> ok(T data){
            return new JsonResult<>(2000,"success",data);
        }
        public static <T> JsonResult<T> ok(){
            return new JsonResult<>(2000,"success",null);
        }
        public static <T> JsonResult<T> fail(Integer code,String message){
            return new JsonResult<>(code,message,null);
        }
        public static <T> JsonResult<T> fail(){
            return new JsonResult<>(5000,"服务异常",null);
        }


        private JsonResult(Integer code, String message, T data) {
            this.code = code;
            this.message = message;
            this.data = data;
        }

        public Integer getCode() {
            return code;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public T getData() {
            return data;
        }

        public void setData(T data) {
            this.data = data;
        }
    }


